using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using Musicman.Business;
using Musicman.Entities;

namespace Musicman.SAL
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    
    [WebService(Namespace="http://vpankovic.musicman.com/webservices")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class AuthenticationService : System.Web.Services.WebService
    {
        public AuthHeader Authentication;

        
        [WebMethod]
        [SoapHeader("Authentication", Direction = SoapHeaderDirection.InOut)]
        public bool LoggIn()
        {
            Musicman.Entities.User user = DataManager.Instance.LoggInUser(Authentication.user.Emailaddress, Authentication.user.Password, false);
            this.Authentication.user = user;
            if (user != null)
            {
                this.Authentication.userLogs = DataManager.Instance.GetClientLoginCount((long)user.Personid);
                this.Authentication.totalLogs = DataManager.Instance.GetTotalClientLoginCount();
            }
            return user != null;
        }

        [WebMethod]
        [SoapHeader("Authentication", Direction = SoapHeaderDirection.InOut)]
        public bool UpdateUserProfile()
        {
            bool res = DataManager.Instance.SaveUser(Authentication.user);
            return res;
        }
    }


    public class AuthHeader : SoapHeader
    {
        public User user;
        public int totalLogs;
        public int userLogs;
    }
}
